/*
 * 类名称:TransportController.java
 * 包名称:com.platform.controller
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2020-03-27 10:23:51        lipengjun     初版做成
 *
 * Copyright (c) 2019-2019 微同科技
 */
package com.platform.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.annotation.SysLog;
import com.platform.utils.R;
import com.platform.controller.AbstractController;
import com.platform.entity.TransportEntity;
import com.platform.service.TransportService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Controller
 *
 * @author lipengjun
 * @date 2020-03-27 10:23:51
 */
@RestController
@RequestMapping("transport")
public class TransportController extends AbstractController {
    @Autowired
    private TransportService transportService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("transport:list")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<TransportEntity> list = transportService.queryAll(params);

        return R.ok().put("list", list);
    }

    /**
     * 分页查询
     *
     * @param params 查询参数
     * @return R
     */
    @GetMapping("/list")
    @RequiresPermissions("transport:list")
    public R list(@RequestParam Map<String, Object> params) {
        Page page = transportService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return R
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("transport:info")
    public R info(@PathVariable("id") Integer id) {
        TransportEntity transport = transportService.getById(id);

        return R.ok().put("transport", transport);
    }

    /**
     * 新增
     *
     * @param transport transport
     * @return R
     */
    @SysLog("新增")
    @RequestMapping("/save")
    @RequiresPermissions("transport:save")
    public R save(@RequestBody TransportEntity transport) {

        transportService.add(transport);

        return R.ok();
    }

    /**
     * 修改
     *
     * @param transport transport
     * @return R
     */
    @SysLog("修改")
    @RequestMapping("/update")
    @RequiresPermissions("transport:update")
    public R update(@RequestBody TransportEntity transport) {

        transportService.update(transport);

        return R.ok();
    }

    /**
     * 根据主键删除
     *
     * @param ids ids
     * @return R
     */
    @SysLog("删除")
    @RequestMapping("/delete")
    @RequiresPermissions("transport:delete")
    public R delete(@RequestBody Integer[] ids) {
        transportService.deleteBatch(ids);

        return R.ok();
    }
}
